package com.aso114.project.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.base.BasesAdapter;
import com.aso114.project.bean.TrueQuestionBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SatPractieAdapter extends BasesAdapter<SatPractieAdapter.ViewHolder> {

    private List<TrueQuestionBean> mDatas;
    private Context mContext;

    private OnItemClickListener mClickListener;

    public SatPractieAdapter(Context context, List<TrueQuestionBean> datas) {
        super(context);
        this.mContext = context;
        this.mDatas = datas;
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(getInflater().inflate(R.layout.satpractice_item, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvItem.setText(mDatas.get(position).getPaperTitle());
        if (mDatas.get(position).getUserCount().equals("")) {
            holder.Score.setText("已经做过0次");
        } else {
            holder.Score.setText("已经做过" + mDatas.get(position).getUserCount() + "次");
        }
        if (mDatas.get(position).getExamUserCount().equals("")) {
            holder.ExamDuration.setText("0人已做:");
        } else {
            holder.ExamDuration.setText(mDatas.get(position).getExamUserCount() + "人已做");
        }

        holder.DifficultyFactor.setText("难度:" + mDatas.get(position).getDifficultyFactor());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mClickListener != null) {
                    mClickListener.onItemClick(position);
                }
            }
        });
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_item)
        TextView tvItem;
        @BindView(R.id.DifficultyFactor)
        TextView DifficultyFactor;
        @BindView(R.id.ExamDuration)
        TextView ExamDuration;
        @BindView(R.id.Score)
        TextView Score;
        @BindView(R.id.item_view)
        LinearLayout itemView;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mClickListener = listener;
    }

    public interface OnItemClickListener {
        void onItemClick(int postion);
    }

}

